/**
 * 
 */
package ar.unq.edu.svnpermission.homes;

import java.util.HashMap;
import java.util.Map;

import org.uqbar.commons.model.Entity;
import org.uqbar.commons.model.Home;

import ar.unq.edu.svnpermission.persist.Db4oHomeFactory;
import ar.unq.edu.svnpermission.persist.HomeFactory;

/**
 * 
 * Singleton que provee el acceso a las Homes de la aplicacion
 * @author nicolas
 *
 */
public class SvnPermission {
	private static Map<Class<?>, Home<?>> homes;

	@SuppressWarnings("unchecked")
	public static synchronized <T extends Entity, H extends Home<T>> H getHome(Class<T> type,Class<H> home) {
		if (homes == null) {
			initialize();
		}
		return (H) homes.get(type);
	}

	public static void initialize(HomeFactory factory) {
		//HARDCODED: coupled with in-memory homes. 
		Map<Class<?>, Home<?>> homes = new HashMap<Class<?>, Home<?>>();
		factory.addHomes(homes);
		SvnPermission.homes = homes;
	}
	
	public static synchronized void initialize() {
		initialize(new Db4oHomeFactory()); 
	}
}
